using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
///
/// Sprite事件行为
///
/// ----------------------------------------
/// 作者：hep
/// 创建时间：2023/06/28 18:02
/// ----------------------------------------
/// </summary>
[RequireComponent(typeof(BoxCollider2D))]
public class SpriteEventBehaviour : MonoBehaviour
{
    private BoxCollider2D collider2D;


    private Action mouse_up_callback;
    private Action mouse_down_callback;
    private Action mouse_drag_callback;



    private void Awake()
    {
        if (collider2D == null)
        {
            collider2D = gameObject.GetComponent<BoxCollider2D>();
            if (collider2D == null)
            {
                collider2D = gameObject.AddComponent<BoxCollider2D>();
            }
        }
        collider2D.isTrigger = true;
    }


    public void Register_MouseUp(Action _callback)
    {
        mouse_up_callback = _callback;
    }
    public void Register_MouseDown(Action _callback)
    {
        mouse_down_callback = _callback;
    }
    public void Register_MouseDrag(Action _callback)
    {
        mouse_down_callback = _callback;
    }


    //鼠标抬起事件
    private void OnMouseUp()
    {
        if (mouse_up_callback != null)
        {
            mouse_up_callback.Invoke();
        }
    }

    /// <summary>
    /// 鼠标按下事件
    /// </summary>
    private void OnMouseDown()
    {
        if (mouse_down_callback != null)
        {
            mouse_down_callback.Invoke();
        }
    }

    /// <summary>
    /// 鼠标拖拽事件
    /// </summary>
    private void OnMouseDrag()
    {
        if (mouse_drag_callback != null)
        {
            mouse_drag_callback.Invoke();
        }
    }

}
